package org.example.BinaryTree;

import java.util.ArrayList;
import java.util.List;

public class Find_the_value_in_the_bottom_left_corner_of_the_tree {
    public static ArrayList<List<Integer>> arrayList = new ArrayList<>();
    public static void main(String[] args) {
        //找树左下角的值

        //给定一个二叉树的 根节点 root，请找出该二叉树的 最底层 最左边 节点的值。
        //假设二叉树中至少有一个节点。
        TreeNode node1 = new TreeNode(1);
        TreeNode node2 = new TreeNode(2);
        TreeNode node3 = new TreeNode(3);
        TreeNode node4 = new TreeNode(4);
        TreeNode node5 = new TreeNode(5);
        TreeNode root = new TreeNode(0);
        TreeNode node6 = new TreeNode(6);
        TreeNode node7 = new TreeNode(7);
        root.left = node1;
        root.right = node2;
        node1.left = node3;
        node1.right = node4;
        node2.left = node5;
        node2.right = node6;
        node5.left = node7;
        get(root,0);
        Integer i = arrayList.get(arrayList.size() - 1).get(0);
        System.out.println(i);
    }
    public static void get(TreeNode root,int deep) {
        if (root==null) return;
        deep++;
        if (arrayList.size()<deep){
            ArrayList<Integer> item = new ArrayList<>();
            item.add(root.val);
            arrayList.add(item);
        }else {
            arrayList.get(deep-1).add(root.val);
        }
        get(root.left,deep);
        get(root.right,deep);
    }
}
